<template>
  <div class="about">
    <el-page-header @back="$router.go(-1)" content="新增教学楼"></el-page-header>
    <header>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="form-Classroom">
        <el-form-item label="教学楼名称：" prop="name">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
      </el-form>
      <el-button type="primary" plain class="btn" @click="search()">确定</el-button>
    </header>
  </div>
</template>


<script>
export default {
  data() {
    return {
      form: {},

      rules: {
        name: [{ required: true, message: "教学楼必选！", trigger: "blur" }],
      },
    };
  },

  created() {},

  methods: {
    // 查询
    search() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$axios({
            url: "/api/buildingAdd",
            method: "post",
            data: {
              name: this.form.name,
            },
          }).then((res) => {
            if (res._RejCode === "00000000") {
              this.$message({
                message: "新增成功",
                type: "success",
              });
              this.$refs.form.resetFields();
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style  scoped>
header {
  width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.btn {
  width: 40%;
}
</style>
